<?php

class StdLibComparisonOperators implements CliLibrary
{
	private static $operators = array(
		ExpOperator::TYPE_LEFT => array(
			'<' => array(PREC_LTGT, 'op_lt'),
			'>' => array(PREC_LTGT, 'op_gt'),
			'<=' => array(PREC_LTGT, 'op_lteq'),
			'>=' => array(PREC_LTGT, 'op_gteq'),
			'<>' => array(PREC_EQNEQ, 'op_neq'),
			'!=' => array(PREC_EQNEQ, 'op_neq'),
			'==' => array(PREC_EQNEQ, 'op_eq'),
		),
	);

	public static function addLibrary (CliMode $mode)
	{
		$mode->addOperators(__CLASS__, self::$operators);
	}

	public static function op_lt (ArgContext $args)
	{
		$args->operandCount(2);
		return $args->toNumber(0) < $args->toNumber(1);
	}

	public static function op_gt (ArgContext $args)
	{
		$args->operandCount(2);
		return $args->toNumber(0) > $args->toNumber(1);
	}

	public static function op_lteq (ArgContext $args)
	{
		$args->operandCount(2);
		return $args->toNumber(0) <= $args->toNumber(1);
	}

	public static function op_gteq (ArgContext $args)
	{
		$args->operandCount(2);
		return $args->toNumber(0) >= $args->toNumber(1);
	}

	public static function op_neq (ArgContext $args)
	{
		$args->operandCount(2);
		return $args->toNumber(0) != $args->toNumber(1);
	}

	public static function op_eq (ArgContext $args)
	{
		$args->operandCount(2);
		return $args->toNumber(0) == $args->toNumber(1);
	}
}